package com.example.administrator.jiangsu2021_3;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.com.newland.nle_sdk.responseEntity.User;
import cn.com.newland.nle_sdk.responseEntity.base.BaseResponseEntity;
import cn.com.newland.nle_sdk.util.NCallBack;
import cn.com.newland.nle_sdk.util.NetWorkBusiness;
import retrofit2.Call;

public class SignIn extends AppCompatActivity {
    private EditText username,password;
    private Button btn_signin;
    private NetWorkBusiness netWorkBusiness;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);
        init();
        btn_signin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Singin();
                Intent intent=new Intent(SignIn.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
    private void init(){
        username=findViewById(R.id.et_username);
        password=findViewById(R.id.et_passowrd);
        btn_signin=findViewById(R.id.btn_signin);
    }
    private void  Singin(){
        String path="http://api.nlecloud.com:80";
        netWorkBusiness=new NetWorkBusiness("",path);
        netWorkBusiness.signIn(new cn.com.newland.nle_sdk.requestEntity.SignIn("13646795937", "jhc210210"), new NCallBack<BaseResponseEntity<User>>(this) {
            @Override
            protected void onResponse(BaseResponseEntity<User> response) {
                if(response!=null){
                    if(response.getStatus()==0){
                        SaveandGet.saveAcc(response.getResultObj().getAccessToken(),SignIn.this);

                    }
                }
            }
            @Override
            public void onFailure(Call<BaseResponseEntity<User>> call, Throwable t) {
                Toast.makeText(SignIn.this,"登陆失败"+t.getMessage(),Toast.LENGTH_SHORT
                ).show();
            }
        });

    }
}
